package com.smarttest.portal.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smarttest.portal.pojo.Authgroup;
import com.smarttest.portal.pojo.Authuser;
import com.smarttest.portal.service.LoginService;

@Controller
@RequestMapping("/login")
public class LoginController {
	@Resource
	LoginService loginService;
	
	/**
	 * 用户登陆
	 * @param user
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/doLogin.action")
	public Map<String,Object> doLoginByAccount(HttpServletRequest request, String name, String userKey){
		Map<String,Object>map=new HashMap<String, Object>();
		Integer i=null;
		Authuser userBean=loginService.getUserInfoByAccount(name,userKey);
		if(userBean!=null){
			if(userKey.equals(userBean.getUserKey())){
				i=0;//登陆成功
				map.put("id", userBean.getId());
				request.getSession().setAttribute("user", userBean);
				request.getSession().setAttribute("name", userBean.getName());
				request.getSession().setAttribute("ID", userBean.getId());
			}else{
				i=1;//登录密码不正确
			}
		}else{
				i=2;//此账号不存在
		}
		map.put("i", i);
		return map;
	}
	
}
